﻿using System;
using System.Diagnostics;

namespace Tinter.Models
{
    public abstract partial class EntityBase
    {
        #region ChangeTracking

        protected virtual void OnPropertyChanged()
        {
            var methodName = new StackTrace(1, false).GetFrame(0).GetMethod().Name;

            if (methodName.StartsWith("set_"))
            {
                OnPropertyChanged(methodName.Remove(0, 4));
            }
            else
            {
                throw new InvalidOperationException("This method should only be called in property setter.");
            }
        }

        protected virtual void OnPropertyChanged(String propertyName)
        {
            // Not implemented.
        }

        #endregion
    }
}
